<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增页面</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>

    <script type="text/javascript">
        function addInfo() {
            var formData = new FormData();
            var img_file = document.getElementById("in8");
            var fileObj = img_file.files[0];
            var name = $("#in2").val();
            var location = $("#in3").val();
            var keyword = $("#in4").val();
            var type = $("#in5").val();
            var distance = $("#in6").val();
            var product = $("#in7").val();
            formData.append("picture",fileObj);
            formData.append("location",location);
            formData.append("keyword",keyword);
            formData.append("type",type);
            formData.append("distance",distance);
            formData.append("product",product);
            formData.append("name",name);
            $.ajax({
                type:"POST",
                dataType:"json",
                url:"http://139.199.210.127:8080/addInfo",
                processData : false,
                async:false,
                contentType : false,
                data:formData,
                success:function (data) {
                    if(data='1'){
                        alert("新增成功～！");
                        window.location.href='index.html';
                    }else {
                        alert("新增失败～！请联系管理员！")
                    }
                },
                error:function () {
                    alert("error");
                }
            });
        }
    </script>

</head>
<body>

<form method="post" action="#" enctype="multipart/form-data">
    <table>
        <tr>
            <td>name</td>
            <td><input type="text" id="in2" name="name"></td>
        </tr>
        <tr>
            <td>location</td>
            <td><input type="text" id="in3" name="location"></td>
        </tr>
        <tr>
            <td>keyword</td>
            <td><input type="text" id="in4" name="keyword"></td>
        </tr>
        <tr>
            <td>type</td>
            <td><input type="text" id="in5" name="type"></td>
        </tr>
        <tr>
            <td>distance</td>
            <td><input type="text" id="in6" name="distance"></td>
        </tr>
        <tr>
            <td>product</td>
            <td><input type="text" id="in7" name="product"></td>
        </tr>
        <tr>
            <td>picture</td>
            <td><input type="file" id="in8" name="picture"></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="button" onclick="addInfo()" value="提交"></td>
        </tr>
    </table>
</form>

</body>
</html>